﻿using ServiceStack.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.EventServices.Providers
{
    internal class RedisSubscribeReceiver
    {
        private RedisClient redisClient;
        private Action<string> funResolver;

        public RedisSubscribeReceiver(RedisClient redis, Action<string> funResolver)
        {
            this.redisClient = redis;
            this.funResolver = funResolver;
        }

        public void Start(object state)
        {
            UTF8Encoding ue = new UTF8Encoding();

            byte[][] bytes = null;
            while (true)
            {
                bytes = this.redisClient.ReceiveMessages();
                string msg = ue.GetString(bytes[2]);
                this.funResolver(msg);
            }
        }
    }
}
